#!/bin/sh
# syslinux
# Builds from https://github.com/puppylinux-woof-CE/petbuilds
# File auto generated by ./mk_petbuild.sh. Edit as necessary.

. ../func
. ../build.conf

URL=https://www.kernel.org/pub/linux/utils/boot/syslinux
PKG=syslinux
VER=4.07
COMP=tar.xz
DESC="lighweight bootloaders"
DEPS=
CAT=BuildingBlock
DESKTOP=syslinux.desktop
BUILD=
CWD=$(pwd)
[ -z "$MWD" ] && MWD=$(dirname $CWD)
[ -z "$BUILD" ] && BUILD=$DEF_BUILD
# comment these 2 below if you use a custom package() function
[ -f "$DESKTOP" ] || DESKTOP=not
[ -z "$DEPS" ] && DEPS=not

ARCH=$(uname -m)
case $ARCH in # set in build.conf
 *64) 	LIBDIR=$LIBCONF64 
		FLAGS=$CF64;;
 arm*)	LIBDIR=$LIBCONFarm
		FLAGS="-O2" ;;
 i686) 	LIBDIR=$LIBCONF32 
		FLAGS=$CF32;;
	*) 	LIBDIR=$LIBCONF32 
		FLAGS="-O2 -march=$ARCH -mtune=$ARCH";;
esac

# main

retrieve ${PKG}-${VER}.${COMP}
extract ${PKG}-${VER}.${COMP}

cd ${PKG}-${VER}
make cleam
make installer
cd -

origin=${PKG}-${VER}
installdir=${PKG}-install

mkdir -p ${installdir}/usr/bin
mkdir -p ${installdir}/usr/lib
mkdir -p ${installdir}/usr/share/syslinux
ln -s ../../usr/share/syslinux ${installdir}/usr/lib/syslinux

find ${origin} -name '*.c32' | grep -v samples | \
while read f ; do
	install -v $f ${installdir}/usr/share/syslinux
done

find ${origin} -name '*.bin' -o -name '*.sys' -o -name '*.mbr' -o -name '*.bss' | \
while read f ; do
	install -v $f ${installdir}/usr/share/syslinux
done

install -v -m 0755 ${origin}/extlinux/extlinux ${installdir}/usr/bin/
install -v -m 0755 ${origin}/linux/syslinux ${installdir}/usr/bin/
install -v -m 0755 ${origin}/linux/syslinux-nomtools ${installdir}/usr/bin/

install -v ${origin}/utils/* ${installdir}/usr/bin/
chmod +x ${installdir}/usr/bin/*
rm -f ${installdir}/usr/bin/*.c
rm -f ${installdir}/usr/bin/*.h
rm -f ${installdir}/usr/bin/*.in
rm -f ${installdir}/usr/bin/*.o
rm -f ${installdir}/usr/bin/Makefile*

install -v ${origin}/memdisk/memdisk ${installdir}/usr/share/syslinux/
install -v ${origin}/gpxe/gpxelinux.0 ${installdir}/usr/share/syslinux/
install -v ${origin}/gpxe/gpxelinuxk.0 ${installdir}/usr/share/syslinux/

package_std $PKG $VER $ARCH $DESKTOP "$DESC" $DEPS $CAT
